home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / utils / Makedep / print.c < prev   
C/C++ Source or Header  |  1990-12-23  |  3KB  |  139 lines

  1. /*
  2.  * Module which prints out the dependencies of each source file to the
  3.  * file OutputFileName.
  4.  */
  5.  
  6.  
  7. #include "makedep.h"
  8.  
  9. extern char *rindex();
  10.  
  11. int CurrentMarkValue;        /* This variable is used to keep track of
  12.                    which marking cycle is currently going
  13.                    on.  Each source file's dependency graph
  14.                    is traversed using a new value of
  15.                    this variable.  Dependency records are
  16.                    marked to avoid infinite recursions
  17.                    through a possibly cyclic dependency
  18.                    graph. */
  19.  
  20.  
  21. /*
  22.  * PrintDependencies:
  23.  * Prints out the dependencies of each file on the source file list SrcFiles.
  24.  * This is done by recursively printing the dependency list of each file.
  25.  * I.e. each source file's dependency list is traversed and the print
  26.  * routine is called to print the dependency list of each file on the list.
  27.  * Since there may be cycles in the graph of dependencies, a marking scheme
  28.  * is employed.
  29.  */
  30.  
  31. PrintDependencies()
  32.   {
  33.     StringList *p;
  34.  
  35.     if (Debug)
  36.       {
  37.     printf("\nPrintDependencies:\n");
  38.     PrintList(IList, "IList");
  39.     for (p = SrcFiles->next; p != NULL; p = p->next)
  40.       {
  41.         CheckDepList(p);
  42.       }
  43.       }
  44.  
  45.     /* Mark all include file records' state with the same starting value. */
  46.     for (p = IList->next; p != NULL; p = p->next)
  47.       {
  48.     p->state = START_MARK_VALUE;
  49.       }
  50.     CurrentMarkValue = START_MARK_VALUE;
  51.     /* Traverse the list source files and print the dependencies of each. */
  52.     for (p = SrcFiles->next; p != NULL; p = p->next)
  53.       {
  54.         if (p->dep != NULL)    /* Don't print anything if there are no
  55.                    dependencies! */
  56.       {
  57.         CurrentMarkValue++;
  58.         PrintSrcObjFile(p);
  59.         PrintDeps(p);
  60.         printf("\n");
  61.       }
  62.       }
  63.   }
  64.  
  65.  
  66. /*
  67.  * PrintSrcObjFile:
  68.  * Print the source file name with its source extension replaced by its
  69.  * object extension.  Only the base name is printed.
  70.  */
  71.  
  72. PrintSrcObjFile(p)
  73.     StringList *p;
  74.   {
  75.     char name[80];
  76.     char *ptr;
  77.  
  78.     /* Replace the source file's extension with its object extension. */
  79.     strcpy(name, p->str);
  80.     ptr = name + strlen(name);
  81.     while ((ptr != name) && (*ptr != '.'))
  82.       {
  83.     ptr--;
  84.       }
  85.     if (ptr == name)
  86.       {
  87.     fprintf(stderr, "%s: malformed source file name: %s\n", 
  88.         MyName, p->str);
  89.     exit(1);
  90.       }
  91.     ptr++;            /* Get over the '.' */
  92.     strcpy(ptr, ObjExt);
  93.  
  94.     /* Find the start of the base name. */
  95.     ptr = rindex(name, '/');
  96.     if (ptr != NULL)
  97.       {
  98.         ptr++;
  99.       }
  100.     else
  101.       {
  102.         ptr = name;
  103.       }
  104.  
  105.     /* Print out the first part of the appropriate makefile-style 
  106.        dependency line. */
  107.     printf("%s:", ptr);
  108.   }
  109.  
  110.  
  111. /*
  112.  * PrintDeps:
  113.  * Recursive routine which prints out the dependencies for p and invokes
  114.  * itself for all dependencies of dependencies of p.  Uses a marking scheme
  115.  * to avoid cycles in the dependency graph.
  116.  */
  117.  
  118. PrintDeps(p)
  119.     StringList *p;
  120.   {
  121.     DepList *ptr;
  122.     StringList *p1;
  123.  
  124.     /* Traverse the list of immediate dependencies. */
  125.     for (ptr = p->dep; ptr != NULL; ptr = ptr->next)
  126.       {
  127.         p1 = ptr->inclFile;
  128.         if (p1->state < CurrentMarkValue)
  129.       {            /* We've haven't yet seen this dependency. */
  130.         printf(" \\\n\t%s", p1->str);
  131.                 /* Print out the immediate dependency. */
  132.         p1->state = CurrentMarkValue;
  133.                 /* Mark the include file as already seen. */
  134.         PrintDeps(p1);
  135.                 /* Print out the dependency's dependencies. */
  136.       }
  137.       }
  138.   }
  139.